from django.db import models

from dept.models import Department
from role.models import Role

# Create your models here.
class User(models.Model):
    username = models.CharField(max_length=50, unique=True, verbose_name="用户名")
    password = models.CharField(max_length=100, verbose_name="密码")
    avatar = models.CharField(max_length=100,default='https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif', verbose_name="头像")
    active = models.IntegerField(choices=((0, '禁用'),(1, '激活')), default=1, verbose_name='账号状态')
    age = models.IntegerField(verbose_name='年龄')
    email = models.CharField(verbose_name='邮箱', max_length=50, unique=True)
    # 外键 级联关系：保护 角色被占用就阻止删除
    role = models.ForeignKey(Role, on_delete=models.PROTECT)
    dept = models.ForeignKey(Department, on_delete=models.PROTECT)
    create_time = models.DateField(auto_now_add=True)

    class Meta:
        db_table = 'user'